import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from sklearn.metrics import roc_auc_score, roc_curve, auc


def data_preprocessing(path):
    # 1、读取数据
    data = pd.read_csv(path)
    # 2、删除重复数据
    data.drop_duplicates(inplace=True)
    return data


def plt_fig(y_true, y_pred):
    """
    绘制ROC和AUC曲线
    :param y_true: 真实值
    :param y_pred: 预测值
    :return:
    """
    fpr, tpr, thresholds = roc_curve(y_true, y_pred)
    roc_auc = auc(fpr, tpr)  # 或直接用roc_auc_score

    plt.figure(figsize=(8, 6))
    plt.plot(fpr, tpr, color='darkorange', lw=2, label=f'ROC curve (AUC = {roc_auc:.2f})')
    plt.plot([0, 1], [0, 1], color='navy', lw=2, linestyle='--')  # 随机线
    plt.xlim([0.0, 1.0])
    plt.ylim([0.0, 1.05])
    plt.xlabel('False Positive Rate')
    plt.ylabel('True Positive Rate')
    plt.title('Receiver Operating Characteristic (ROC) Curve')
    plt.legend(loc="lower right")
    plt.grid(True)
    plt.show()


if __name__ == '__main__':
    print(data_preprocessing('../../../data/raw/train.csv'))
